package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.ItemInterface;
import cn.stylefeng.guns.sys.modular.system.model.params.ItemInterfaceParam;
import cn.stylefeng.guns.sys.modular.system.model.result.ItemInterfaceResult;
import cn.stylefeng.guns.sys.modular.system.service.ItemInterfaceService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 品项表控制器
 *
 * @author jiangge
 * @Date 2020-09-13 19:50:14
 */
@Controller
@RequestMapping("/itemInterface")
public class ItemInterfaceController extends BaseController {

    private String PREFIX = "/modular/system/itemInterface";

    @Autowired
    private ItemInterfaceService itemInterfaceService;

    /**
     * 跳转到主页面
     *
     * @author jiangge
     * @Date 2020-09-13
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/itemInterface.html";
    }

    /**
     * 新增页面
     *
     * @author jiangge
     * @Date 2020-09-13
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/itemInterface_add.html";
    }

    /**
     * 编辑页面
     *
     * @author jiangge
     * @Date 2020-09-13
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/itemInterface_edit.html";
    }

    /**
     * 新增接口
     *
     * @author jiangge
     * @Date 2020-09-13
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(ItemInterfaceParam itemInterfaceParam) {
        this.itemInterfaceService.add(itemInterfaceParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author jiangge
     * @Date 2020-09-13
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(ItemInterfaceParam itemInterfaceParam) {
        this.itemInterfaceService.update(itemInterfaceParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author jiangge
     * @Date 2020-09-13
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(ItemInterfaceParam itemInterfaceParam) {
        this.itemInterfaceService.delete(itemInterfaceParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author jiangge
     * @Date 2020-09-13
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(ItemInterfaceParam itemInterfaceParam) {
        ItemInterface detail = this.itemInterfaceService.getById(itemInterfaceParam.getItemId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author jiangge
     * @Date 2020-09-13
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(ItemInterfaceParam itemInterfaceParam) {
        return this.itemInterfaceService.findPageBySpec(itemInterfaceParam);
    }

    /**
     * 查询对应品项类别的品项
     */
    @ResponseBody
    @RequestMapping("/itemlist")
    public List<ItemInterfaceResult> itemlist(ItemInterfaceParam itemInterfaceParam) {
        return this.itemInterfaceService.findListByParam(itemInterfaceParam);
    }

    /**
     * 查询对应品项类别的品项-指定的品项，目前只有4个
     */
    @ResponseBody
    @RequestMapping("/specifiedItemlist")
    public List<ItemInterfaceResult> specifiedItemlist(ItemInterfaceParam itemInterfaceParam) {
        return this.itemInterfaceService.findSpecifiedItemlist(itemInterfaceParam);
    }
}


